home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6359 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  95 lines

  1. Path: news.infoserve.net!usenet
  2. From: yang@unix.infoserve.net (Sung Moo Yang)
  3. Newsgroups: comp.lang.c
  4. Subject: [Q] Does free() work?
  5. Date: 24 Feb 1996 04:23:55 GMT
  6. Organization: YANG Laboratories
  7. Message-ID: <4gm3ss$qfa@news.infoserve.net>
  8. NNTP-Posting-Host: d140.infoserve.net
  9. X-Newsreader: WinVN 0.92.5
  10.  
  11. Question on the function free() in MSC 5.1 running on MS-DOS 6.0 on 486 DX2.
  12.  
  13. The library function free() doesn't free memory allocated however _dos_freemem() does.
  14. Example TEST.C uses free() to release memory while TEST2.C uses _dos_freemem() to do so. Result screen was followed respectively.
  15.  
  16. Why doesn't free() release the memory allocated? 
  17. Thanks in advance.
  18.  
  19. Sung Moo
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. /* TEST.C
  29.    Compiled by MSC 5.1 
  30. */
  31. #include <stdlib.h>
  32. main()
  33. {
  34.     char * p;
  35.     p=(char*)malloc(3000);
  36.     free(p);
  37.     system("mem/mtest");
  38.     }
  39.  
  40. ------------------- RESULT SCREEN --------------
  41.  
  42. C:\TEMP>test
  43.  
  44. TEST is using the following memory:
  45.  
  46.   Segment  Region       Total        Type
  47.   -------  ------  ----------------  --------
  48.    01545                544    (1K)  Environment
  49.    01567              70928   (69K)  Program
  50.    026B8               3040    (3K)  Data
  51.                    ----------------
  52.   Total Size:         74512   (73K)
  53.  
  54. ---------------------------------------------------
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. /* TEST2.C
  63.    Compiled by MSC 5.1    
  64. */
  65. #include <dos.h>
  66. #include <stdlib.h>
  67. main()
  68. {
  69.     char * p;
  70.     p=(char*)malloc(3000);
  71.     _dos_freemem(FP_SEG(p));
  72.     system("mem/mtest2");
  73.     }
  74.  
  75.  
  76. ------------------- RESULT SCREEN --------------
  77. C:\TEMP>test
  78.  
  79. TEST2 is using the following memory:
  80.  
  81.   Segment  Region       Total        Type
  82.   -------  ------  ----------------  --------
  83.    01545                544    (1K)  Environment
  84.    01567              70944   (69K)  Program
  85.                    ----------------
  86.   Total Size:         71488   (70K)
  87.  
  88. -------------------------------------------------
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.